package com.easydisk.file.service.impl;

import com.easydisk.constant.FileConstant;
import com.easydisk.file.model.vo.UserFileVO;
import com.easydisk.file.service.RecycleService;
import com.easydisk.file.service.ShareService;
import com.easydisk.file.service.UploadFileService;
import com.easydisk.file.service.UserFileService;
import com.easydisk.common.util.StringListUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RecycleServiceImpl implements RecycleService {

    @Autowired
    private UserFileService userFileService;

    @Autowired
    private ShareService shareService;

    @Autowired
    private UploadFileService uploadFileService;


    @Override
    public List<UserFileVO> getRecycleList(Long userId) {
        return userFileService.getUserFileList(null, FileConstant.ALL_FILE_TYPE,
                userId, FileConstant.DelFlagEnum.YES.getCode());

    }

    @Override
    public void restore(String fileIds, Long userId) {
        userFileService.restoreUserFiles(fileIds, userId);
        String allAvailableFileIdByFileIds = userFileService.getAllAvailableFileIdByFileIds(fileIds);
        shareService.refreshShareStatus(StringListUtil.string2LongList(allAvailableFileIdByFileIds));
    }

    @Override
    public void delete(String fileIds, Long userId) {
        uploadFileService.physicalDeleteUserFiles(fileIds, userId);
    }
}
